package com.itheima.test;

import com.tanhua.AppServerApplication;
import com.tanhua.autoconfig.template.HuanXinTemplate;
import com.tanhua.commons.utils.Constants;
import com.tanhua.dubbo.api.TestSoulApi;
import com.tanhua.dubbo.api.UserApi;
import com.tanhua.model.domain.User;
import com.tanhua.model.mongo.Option;
import com.tanhua.model.mongo.Question;
import com.tanhua.model.mongo.TestList;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@SpringBootTest(classes = AppServerApplication.class)
@RunWith(SpringRunner.class)
public class huanxinText {
    @DubboReference
    private UserApi userApi;
    @Autowired
    private HuanXinTemplate huanXinTemplate;
    @DubboReference
    private TestSoulApi testSoulApi;

    //添加问卷数据
    @Test
    public void  text(){
        TestList testList = new TestList();
        testList.setStar(2);
        testList.setCover("https://tanhua-dev.oss-cn-zhangjiakou.aliyuncs.com/images/test_soul/qn_cover_01.png");
        testList.setLevel("超级");
        testList.setName("超能力者");
        List<Question> questions=new ArrayList<>();
        for (int i = 0; i <10 ; i++) {
            Question question=new Question();
            question.setId(UUID.randomUUID().toString());
            question.setQuestion("超电池炮是谁"+i);
            List<Option> list=new ArrayList<>();
            Option option=new Option();
            option.setId("1");
            option.setOption("御坂美琴"+i);
            Option option2=new Option();
            option2.setId("2");
            option2.setOption("御坂美琴2"+i);
            list.add(option);
            list.add(option2);
            question.setOptions(list);
            questions.add(question);
        }
        testList.setQuestions(questions);

        testSoulApi.save(testList);
    }
    //批量注册
    @Test
    public void register() {
        System.out.println(111);
        List<User> users = userApi.findAll();
        for (User user : users) {
            Boolean create = huanXinTemplate.createUser("hx" + user.getId(), "123456");
            if (create) {
                user.setHxUser("hx" + user.getId());
                user.setHxPassword(Constants.INIT_PASSWORD);
                userApi.update(user);
            }
        }
    }
}
